home *** CD-ROM | disk | FTP | other *** search
- var PhProxy_object ;
-
- //create desire url for phproxy or glype
- var PhProxy_url_creator = {
- addressbar_view_mode : {
- bin2hexOneDig : function (input) {
- if(input=='0000')return '0';
- if(input=='00') return '0';
- if(input=='0001')return '1';
- if(input=='01') return '1';
- if(input=='0010')return '2';
- if(input=='10') return '2';
- if(input=='0011')return '3';
- if(input=='11') return '3';
- if(input=='0100')return '4';
- if(input=='0101')return '5';
- if(input=='0110')return '6';
- if(input=='0111')return '7';
- if(input=='1000')return '8';
- if(input=='1001')return '9';
- if(input=='1010')return 'a';
- if(input=='1011')return 'b';
- if(input=='1100')return 'c';
- if(input=='1101')return 'd';
- if(input=='1110')return 'e';
- if(input=='1111')return 'f';
- },
- bin2hex : function (input) {
- return ( this.bin2hexOneDig(input.substr(0,2)) +
- this.bin2hexOneDig(input.substr(2,4)) +
- this.bin2hexOneDig(input.substr(6,4)) )
- },
- get : function() {
- if(PhProxy_prefs.read_str('PrType')=="2") //glype mode 1
- return 'b5/';
- if(PhProxy_prefs.read_str('PrType')=="3") //glype mode 2
- return '&b=29';
- else{
- var sCntr=PhProxy_prefs.read_str('Contr').split('|');
- var OutPut=sCntr[0]+sCntr[1]+sCntr[2]+sCntr[3]+sCntr[4]+(PhProxy_prefs.read_bool('useROT13') ? '10' : '01')+sCntr[5]+sCntr[6]+sCntr[7];
- if(PhProxy_prefs.read_str('PrType')=="1")
- return this.bin2hex(OutPut);
- else
- return OutPut ;
- }
- }
- },
-
- glype_proxify : function (str){
- str=str.substr(4); // remove http
- str=str.replace(/\/.\//g,'/');
- str=str.replace(/\/\//g,'/');
- str=str.replace(/:\//g,'://');
-
- str = PhProxy_Base64.encode(str);
- str=encodeURIComponent(str); //instead of $url = rawPh_urlEncode($url);
-
- const sURL=PhProxy_prefs.read_str('curURL');
-
- if(PhProxy_prefs.read_str('PrType')=="2"){
- //chunk_split($url,rand(7,14),'/'))
- tSTR = "";
- for(i=0;i<str.length;i+=8)
- tSTR+=str.substr(i,8)+'/';
- str = tSTR;
- str = str.replace(/\%/g,'_');
- str = sURL + PhProxy_prefs.read_str('glypeIndex') + "/"+ str + this.addressbar_view_mode.get();
- return str;
- }
- else{
- str = sURL + PhProxy_prefs.read_str('glypeIndex') + "?u="+ str + this.addressbar_view_mode.get();
- return str;
- }
- },
- glype_deproxify : function (str){
- //remove base
- if(PhProxy_prefs.read_str('PrType')=="2"){
- charLocation=str.indexOf(PhProxy_prefs.read_str('glypeIndex'));
- if(charLocation!=-1) str=str.substr(charLocation+10);
- }
- else{
- charLocation=str.indexOf(PhProxy_prefs.read_str('glypeIndex') + '?u=');
- if(charLocation!=-1) str=str.substr(charLocation+13);
- charLocation=str.indexOf('&b=');
- if(charLocation!=-1) str=str.substr(0,charLocation);
- }
- str=str.replace(/\/b[0-9]{1,3}\/(?:f[a-z]{1,10}\/?)?/, '/');
- str=str.replace(/\//g, '');
- str=str.replace(/_/g, '%');
- str=PhProxy_Glype_decode.run(str);
- str="http"+PhProxy_Base64.decode(str, "Glype");
- str=str.replace(/&/g, '&');
- str=str.replace(/ /g, '%20');
-
- return str;
- },
- phproxy_proxify : function(str){
- const sURL=PhProxy_prefs.read_str('curURL');
-
- if (PhProxy_prefs.read_bool('useROT13'))
- return sURL + PhProxy_prefs.read_str('phpIndex') + '?q=' + PhProxy_Rot13.encode(str)+ '&hl='+this.addressbar_view_mode.get();
- else
- return sURL + PhProxy_prefs.read_str('phpIndex') + '?q=' + PhProxy_Base64.encode(str)+ '--&hl='+this.addressbar_view_mode.get();
- },
- phproxy_deproxify : function(str){
- if (PhProxy_prefs.read_bool('useROT13'))
- return PhProxy_Rot13.decode(str);
- else
- return PhProxy_Base64.decode(str);
- },
- proxify : {
- phf_check_if_url_is_video_site : function (data) {
- if( !data.match(/[A-Za-z0-9_.\/\?=\:]*keepvid[A-Za-z0-9_.\/\?=\:]*/) && //check if url not contains "keepvid.com"
-
- ( data.match(/[A-Za-z0-9_.\/\?=\:]*watch[A-Za-z0-9_.\/\?=\:]*/) || // Check youtube file infomrat "www.youtube.com/watch?v=???"
- data.match(/[A-Za-z0-9_.\/\?=\:]*\/v\/[A-Za-z0-9_.\/\?=\:]*/) ) // Check youtube file infomrat "http://www.youtube.com/v/???"
- )
- return true;
- else
- return false
- },
- apply : function (str) {
- //Check URL for Youtube
- if ( PhProxy_prefs.read_bool('youTubeV') && this.phf_check_if_url_is_video_site( str ) )
- str="http://keepvid.com/?url=" + str;
- //Caching; http://ostermiller.org/bookmarklets/cache.html; Copyright (c) 2004-2007 by Stephen Ostermiller
- if ( !this.phf_check_if_url_is_video_site(str) && (PhProxy_prefs.read_str('privacyLevel') == '1' || PhProxy_prefs.read_str('privacyLevel') == '2') ) {
- switch (PhProxy_prefs.read_str('cacheType')) {
- case '0': //Google Cache
- str = "http://www.google.com/search?q=cache:" + escape(str.replace(/^http\:\/\/(.*)$/,"$1"));
- break;
- case '1': //Wayback Machine
- str = "http://web.archive.org/web/*/" + str;
- break;
- default: //Coral Cache
- str = str.replace( /^http\:\/\/([^\/\@]+)\/(?:)/, "http://"+"$1".replace("\:",".")+".nyud.net:8090/");
- }
- }
- switch (PhProxy_prefs.read_str('privacyLevel')) {
- case '0': //PhProxy or PhProxy + Cache
- case '2':
- if (PhProxy_prefs.read_str('PrType')=="2" || PhProxy_prefs.read_str('PrType') == "3")
- return PhProxy_url_creator.glype_proxify(str);
- else
- return PhProxy_url_creator.phproxy_proxify(str);
- break;
- default: //Cache only
- return str;
- }
- },
- apply_filter : function (data, type) {
- var sURL = PhProxy_prefs.read_str('curURL');
- //Check url validation
- var test = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/.test(data);
- //
- if (test) {
- if( type=="proxify" )
- if( data.match(sURL) && !this.phf_check_if_url_is_video_site( PhProxy_url_creator.depoxify(data) ) )
- return data;
- else if( data.match(sURL) && this.phf_check_if_url_is_video_site( PhProxy_url_creator.depoxify(data) ) ) // for vedio test on PhProxy sites
- return this.apply(PhProxy_url_creator.depoxify(data));
- else return this.apply(data);
- else
- return PhProxy_url_creator.depoxify(data);
- }
- else{
- var stringsBundle = document.getElementById("Ph.Main.Bundle");
- alert(stringsBundle.getString('Alert5')+' '+data+'\n'+
- stringsBundle.getString('Alert6')+'\n\n'+
- stringsBundle.getString('Alert9')+'\n\thttp://www.google.com\n'+
- stringsBundle.getString('Alert10')+'\n\twww.google.com\n\tgoogle.com\n\t...');
- return false;
- }
- }
- },
- depoxify : function(str){
- if(PhProxy_prefs.read_str('PrType')=="2" || PhProxy_prefs.read_str('PrType')=="3")
- return this.glype_deproxify(str);
- else
- return this.phproxy_deproxify(str);
- }
- }
-
- var PhProxy = {
- selected_page_href: null, //save current url of selected page
- mouse_over_href: null, //save current url of on mouse over
- statusbar_id: null, //save Status bar id
- contextmenu_id: null, //save contextmenu id
- stringsBundle : null,
- unkonwn_server: null,
-
- initial : function() {
- PhProxy_object.statusbar_id = document.getElementById('Ph-Status-Icon');
- PhProxy_object.contextmenu_id = document.getElementById("contentAreaContextMenu");
- //initialize string bundle
- PhProxy_object.stringsBundle = document.getElementById("Ph.Main.Bundle");
- //initialize statusbar
- PhProxy_windows.initial();
- // phv_servers_listener for webpage loads
- gBrowser.addProgressListener(PhProxy_object._URLBar_listener, Components.interfaces.nsIWebProgress.NOTIFY_STATE_DOCUMENT);
- //Context menu on pupup showing
- PhProxy_object.contextmenu_id.addEventListener("popupshowing", PhProxy_object.on_contextmenu_fire, false);
- //Add servers to statusbar
- var addServersToStatusbar = function () {
- var addOneServer = function (label, value, dServer) {
- var menuitem = document.createElement("menuitem");
- menuitem.setAttribute('label', label);
- menuitem.setAttribute('value', value);
- menuitem.setAttribute('onclick', "PhProxy.statusbar_menu(label,value," + dServer +")");
- document.getElementById("Ph.Status.PH7.menupopup").appendChild(menuitem);
- }
- //Add default Server
- addOneServer (this.stringsBundle.getString('dServer'), '', true);
- //Add Seperator
- document.getElementById("Ph.Status.PH7.menupopup").appendChild(document.createElement("menuseparator"));
- //Add other servers
- var sURL = PhProxy_prefs.read_str('sURL').split('|');
- for (var i = 0 ; i < 16 ; i += 2)
- addOneServer (sURL[i], sURL[i+1], false);
- }();
- //Show welcome Screen
- /* MUST PLACE BEFORE default_server.update();*/
- /*MUST PLACE AFTER Add servers to statusbar*/
- PhProxy_object.show_welcome_screen_if_needed();
- //update default server
- PhProxy_object.default_server.update();
- //Addressbar icon
- document.getElementById('urlbar').setAttribute('phproxy-show-icon', PhProxy_prefs.read_str('showAddressbar'));
- //Statusbar radio box
- document.getElementById('Ph-Status-PH8-RadioG1').childNodes[parseInt(PhProxy_prefs.read_str('privacyLevel'))].setAttribute("checked", true);
- document.getElementById('Ph-Status-PH8-RadioG2').childNodes[parseInt(PhProxy_prefs.read_str('cacheType'))].setAttribute("checked", true);
- },
-
- open_in : {
- ioSvc : Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService),
-
- current_tab : function(data){
- var referer = this.ioSvc.newURI(PhProxy_prefs.read_str('curURL'), null, null);
- gBrowser.loadURI(data,referer);
- },
- new_tab : function(data){
- var referer = this.ioSvc.newURI(PhProxy_prefs.read_str('curURL'), null, null);
- gBrowser.addTab(data,referer);
- }
- },
-
- _page_listener : {
- apply : function(){
- window.addEventListener("mouseover", PhProxy_object.correct_statusbar_text, false);
- window.addEventListener("mouseout", PhProxy_object.correct_statusbar_text_distroy, false);
- //window.addEventListener("keypress", PhProxy_object.copy_decode_url_to_clipboard,false);
- },
- remove : function(){
- window.removeEventListener("mouseover", PhProxy_object.correct_statusbar_text, false);
- window.removeEventListener("mouseout", PhProxy_object.correct_statusbar_text_distroy, false);
- //window.removeEventListener("keypress", PhProxy_object.copy_decode_url_to_clipboard, false);
- }
- },
-
- _URLBar_listener : {
- QueryInterface: function(aIID){
- if (aIID.equals(Components.interfaces.nsIWebProgressListener) || aIID.equals(Components.interfaces.nsISupportsWeakReference) || aIID.equals(Components.interfaces.nsISupports))
- return this;
- throw Components.results.NS_NOINTERFACE;
- },
- onLocationChange: function(aProgress, aRequest, aURI){ PhProxy.process_new_URL(aURI);},
- onStateChange: function() {},
- onProgressChange: function() {},
- onStatusChange: function() {},
- onSecurityChange: function() {},
- onLinkIconAvailable: function() {}
- },
- statusbar_menu : function(label, value, isItDServer) {
- if (!isItDServer) {
- PhProxy_prefs.write_str('curURL', label);
- switch(value){
- case "0.4": PhProxy_prefs.write_str('PrType', "0"); break;
- case "Glype1": PhProxy_prefs.write_str('PrType', "2"); break;
- case "Glype2": PhProxy_prefs.write_str('PrType', "3"); break;
- default: PhProxy_prefs.write_str('PrType', "1");
- }
- }
- else {
- PhProxy_prefs.write_str('curURL', PhProxy_prefs.read_str('facURL'));
- PhProxy_prefs.write_str('PrType', PhProxy_prefs.read_str('facType'));
- }
- //Change urlbar text to default text
- gURLBar.value = content.document.location.href;
- //force proccess like new loaded tab
- var aURL = {spec:null};
- aURL.spec = content.document.location.href;
- PhProxy_object.process_new_URL(aURL);
- },
-
- terminate : function() {
- gBrowser.removeProgressListener(PhProxy_object._URLBar_listener);
- },
-
- process_new_URL : function(aURI) {
- //for null url
- if(!aURI) {
- PhProxy_object.statusbar_id.setAttribute('status', 'Blue');
- //Remove All Listeners on page
- PhProxy_object._page_listener.remove();
- //Remove notification label
- PhProxy_object.hide_notification_on_unknown_servers();
- //If aURL is null then exit!
- return
- }
- PhProxy_object.selected_page_href = aURI.spec;
-
- if(PhProxy_object.selected_page_href.match(PhProxy_prefs.read_str('curURL'))){
- //Corrent status bar icon color
- PhProxy_object.statusbar_id.setAttribute('status', 'Gray');
- //corrent addressbar url
- var decoded_href = PhProxy_url_creator.depoxify(PhProxy_object.selected_page_href);
- setTimeout(function() {
- gURLBar.value="PH:: " + decoded_href ;
- }, 100);
- //hide notification
- PhProxy_object.hide_notification_on_unknown_servers();
- //apply all requird phv_servers_listener for keyboard & mouse tracking
- PhProxy_object._page_listener.apply();
- }
- else{
- //Search to find new server
- if (PhProxy_object.is_this_vaid_phproxy_server(PhProxy_object.selected_page_href))
- PhProxy_object.show_notification_on_unknown_servers(PhProxy_object.selected_page_href);
- else
- PhProxy_object.hide_notification_on_unknown_servers();
- //Corrent status bar icon color
- PhProxy_object.statusbar_id.setAttribute('status', 'Blue');
- //Remove All Listeners on page
- PhProxy_object._page_listener.remove();
- }
- },
-
- on_addressbar_click : function(){
- if(!/^PH:: */.test(gURLBar.value))
- PhProxy.open_secure(gURLBar.value);
- else
- alert(this.stringsBundle.getString('Alert2'));
- },
-
- on_contextmenu_fire : function(){
- const menuitem1 = document.getElementById("context-PH1");
- const menuitem2 = document.getElementById("context-PH2");
- const menuitem3 = document.getElementById("context-PH3");
- const menuitem4 = document.getElementById("context-PH4");
- const menuitem5 = document.getElementById("context-PH5");
-
- if(!(gContextMenu)) return;
- var sURL = typeof(gContextMenu.linkURL) == "function" ? gContextMenu.linkURL() : gContextMenu.linkURL;
-
- if(menuitem1){
- if(!sURL){
- menuitem1.hidden = menuitem2.hidden = menuitem3.hidden = menuitem4.hidden = menuitem5.hidden = true;
- }
- else if(sURL.match(PhProxy_prefs.read_str('curURL'))){
- menuitem1.hidden = menuitem2.hidden = gContextMenu.onLink;
- menuitem3.hidden = menuitem4.hidden = menuitem5.hidden = !gContextMenu.onLink;
- }
- else{
- menuitem1.hidden = menuitem2.hidden = !gContextMenu.onLink;
- menuitem3.hidden = menuitem4.hidden = menuitem5.hidden = gContextMenu.onLink;
- }
- }
- },
-
- context : function(index){
- var sURL = typeof(gContextMenu.linkURL) == 'function' ? gContextMenu.linkURL() : gContextMenu.linkURL;
- switch(index){
- case 1:
- PhProxy.open_secure(sURL);
- break;
- case 2:
- PhProxy.open_secure_in_new_tab(sURL);
- break;
- case 3:
- data = PhProxy_url_creator.proxify.apply_filter(sURL, "depoxify");
- if( data )
- PhProxy.open_in.current_tab(data);
- break;
- case 4:
- var data = PhProxy_url_creator.proxify.apply_filter(sURL, "depoxify");
- if( data )
- PhProxy.open_in.new_tab(data);
- break;
- default:
- PhProxy.copy_decode_url_to_clipboard(sURL);
- }
- },
-
- show_welcome_screen_if_needed : function() {
- var em = Components.classes["@mozilla.org/extensions/manager;1"]
- .getService(Components.interfaces.nsIExtensionManager);
-
- var addon = em.getItemForID("amin.eft_PhProxy@gmail.com");
- var version = addon.version;
- if(PhProxy_prefs.read_str("currentVersion") != version){
- //Force updating default server
- PhProxy_prefs.write_str("lastUpdate", "0 0 0");
- //Force updating servers
- PhProxy_object.update_servers();
- //Showing welcome screen
- setTimeout(function() {
- var newTab = getBrowser().addTab('http://inbasic.mozdev.org/root/ext1/home/index.htm');
- getBrowser().selectedTab = newTab;
- }, 600);
- PhProxy_prefs.write_str("currentVersion", version);
- }
- },
-
- default_server : {
- _server : {
- statusbar_style: null, //save Status bar id
-
- initial : function(){
- statusbar_style = document.getElementById('Ph-Status-Icon').style;
- statusbar_style.listStyleImage = "url('chrome://inbasicph/skin/statusu.png')";
- //Change status on unknown problems after 2 min
- setTimeout(function() {
- statusbar_image = "url('chrome://inbasicph/skin/status.png')";
- }, 120000);
- },
- finished : function(data){
- //Try to correct received data even if it contains more lines
- data = data.match(/[^\n]*/).toString();
- if (!data) {
- PhProxy_windows.show_alert_in_statusbar('Alert8');
- statusbar_style.listStyleImage = "url('chrome://inbasicph/skin/status.png')";
- return;
- }
- identifier=data.substr(0,40);
- if(identifier=="InBasic>DefualtServer>PhProxy>Code124588"){
- const temp = data.substr(42).split('|');
-
- var nwServer=temp[0];
-
- if(PhProxy_prefs.read_str('facURL')==PhProxy_prefs.read_str('curURL')){
- PhProxy_prefs.write_str('curURL',nwServer);
- switch(temp[1]){
- case "0.4": PhProxy_prefs.write_str('PrType',"0"); break;
- case "Glype1": PhProxy_prefs.write_str('PrType',"2"); break;
- case "Glype2": PhProxy_prefs.write_str('PrType',"3"); break;
- default: PhProxy_prefs.write_str('PrType',"1");
- }
- }
- PhProxy_prefs.write_str('facURL',nwServer);
- switch(temp[1]){
- case "0.4": PhProxy_prefs.write_str('facType',"0"); break;
- case "Glype1": PhProxy_prefs.write_str('facType',"2"); break;
- case "Glype2": PhProxy_prefs.write_str('facType',"3"); break;
- default: PhProxy_prefs.write_str('facType',"1");
- }
-
- PhProxy_windows.show_alert_in_statusbar('Alert7');
- }
- else{
- PhProxy_windows.show_alert_in_statusbar('Alert8');
- }
- statusbar_style.listStyleImage = "url('chrome://inbasicph/skin/status.png')";
- }
- },
-
- update : function (force, num) { //force: true ; update dServer anyway, num: 0 ; current server; num=1; next server, num=-1 ; previews server
- if(!force)
- var force = false;
- if(!num)
- var num = 0;
- var is_default_server_update_time = force || function () {
- //Hidden variables
- switch (PhProxy_prefs.read_str('dServerUpdate')) {
- case '1': //case 1: update per day
- var today = new Date();
- var year = today.getYear();
- var ymd = (today.getMonth()+1) + ' ' + today.getDate() + ' ' + (year+"").substring(2,4);
- if (new Date(PhProxy_prefs.read_str('lastUpdate')) < new Date(ymd)) {
- PhProxy_prefs.write_str('lastUpdate',ymd);
- return true;
- }
- break;
- case '2': //case 2 ; update after restart
- var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
- var browserEnumerator = wm.getEnumerator("navigator:browser");
- var num_of_windows = 0;
- while (browserEnumerator.hasMoreElements()) {
- browserEnumerator.getNext();
- num_of_windows++;
- }
- return (num_of_windows == 1) ;
- break;
- default: //case 0 ; do not update default server
- return false;
- }
- }();
-
- if (is_default_server_update_time) {
- setTimeout(function(){ PhProxy.default_server._server.initial(); }, 5000 - (force ? 4500 : 0) );
- setTimeout(function(){
- var req = new XMLHttpRequest();
-
- req.open('GET', PhProxy_prefs.read_str("Server") + "?request=dServer&num=" + num, true);
- req.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
- req.onreadystatechange = function (aEvt) {
- if (req.readyState == 4){
- if(req.status == 200)
- PhProxy.default_server._server.finished(req.responseText);
- else
- PhProxy.default_server._server.finished(null);
- }
- };
- req.send(null);
- }, 10000 - (force ? 4500 : 0));
- }
- }
- },
-
- update_servers: function() {
- var req = new XMLHttpRequest();
-
- req.open('GET', PhProxy_prefs.read_str("Server") + "?request=servers", true);
- req.channel.loadFlags |= Components.interfaces.nsIRequest.LOAD_BYPASS_CACHE;
- req.onreadystatechange = function (aEvt) {
- if (req.readyState == 4){
- if(req.status == 200) {
- //Try to correct received data even if it contains more lines
- var sURL=req.responseText.match(/[^\n]*/).toString().split("|");
- if(!String(sURL[0]).match('InBasic>ServerInUse>PhProxy>Code124587'))
- return;
- PhProxy_prefs.write_str('UpdateVer', sURL[1]);
- for (var y = 2; y < 18; y += 2) {
- //update menu list in statusbar
- var wm =Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
- var browserEnumerator = wm.getEnumerator("navigator:browser");
- while(browserEnumerator.hasMoreElements()) //maybe more than 1 window opens!!
- {
- var dc = browserEnumerator.getNext().document;
- /*Important note: getElementsByTagName('menuitem')[(y)/2-1].label) doesnt work in this case because window doesnt load yet!*/
- //Fist item is dServer
- dc.getElementById('Ph.Status.PH7.menupopup').getElementsByTagName('menuitem')[(y)/2].setAttribute('label', sURL[y]);
- dc.getElementById('Ph.Status.PH7.menupopup').getElementsByTagName('menuitem')[(y)/2].setAttribute('value', sURL[y+1]);
- }
- }
- //Update prefs
- PhProxy_prefs.write_str('sURL',sURL[2]+'|'+sURL[3]+'|'+sURL[4]+'|'+sURL[5]+'|'+sURL[6]+'|'+sURL[7]+'|'+sURL[8]+'|'+sURL[9]+'|'+sURL[10]+'|'+sURL[11]+'|'+sURL[12]+'|'+sURL[13]+'|'+sURL[14]+'|'+sURL[15]+'|'+sURL[16]+'|'+sURL[17]);
- }
- else {}
- }
- };
- req.send(null);
- },
- /* Webbase functions */
-
- correct_statusbar_text : function(e){
- var target = e.target; //To find href corectlly
- while (target && !("href" in target))
- target = target.parentNode;
- PhProxy_object.mouse_over_href = target ? target.href : "";
-
- //alert(PhProxy_object.mouse_over_href);
-
- if(PhProxy_object.mouse_over_href.match(PhProxy_prefs.read_str('curURL')))
- {
- if(PhProxy_prefs.read_str('infoShow')=='1')
- {
- var sBarDisp = document.getElementById("Ph.Status.ExternalTip");
-
- sBarDisp.label = PhProxy_url_creator.depoxify(PhProxy_object.mouse_over_href);
-
- if(String(sBarDisp.label).length>30){
- sBarDisp.label=String(sBarDisp.label).substr(0,25)+'...'+String(sBarDisp.label).substr(String(sBarDisp.label).length-22,22);
- }
- sBarDisp.showPopup( PhProxy_object.statusbar_id, -1, -1, 'tooltip', 'bottomleft', 'bottomright');
- }
- else if(PhProxy_prefs.read_str('infoShow')=='0')
- {
- document.getElementById("statusbar-display").label ='PH:: ' + PhProxy_url_creator.depoxify(PhProxy_object.mouse_over_href);
- e.preventDefault();
- }
- }
- },
-
- correct_statusbar_text_distroy : function(e){
- //hide popup for mode 2
- var sBarDisp = document.getElementById("Ph.Status.ExternalTip");
- sBarDisp.hidePopup();
-
- PhProxy_object.mouse_over_href=null;
- },
-
- copy_decode_url_to_clipboard : function(e){
-
- if(typeof(e)=="object"){
- if( !( e.charCode==99 && e.ctrlKey && PhProxy_object.mouse_over_href.match(PhProxy_prefs.read_str('curURL'))) ) return;
- var copytext = PhProxy_object.mouse_over_href;
- }
- else
- var copytext = e;
- //Copy to clipboard start
- var str = Components.classes["@mozilla.org/supports-string;1"].
- createInstance(Components.interfaces.nsISupportsString);
- if (!str){
- alert("clipboard copy problem!");
- return ;
- }
- str.data = PhProxy_url_creator.depoxify(copytext);
- var trans = Components.classes["@mozilla.org/widget/transferable;1"].
- createInstance(Components.interfaces.nsITransferable);
- if (!trans){
- alert("clipboard copy problem!");
- return ;
- }
-
- trans.addDataFlavor("text/unicode");
- trans.setTransferData("text/unicode", str, copytext.length * 2);
-
- var clipid = Components.interfaces.nsIClipboard;
- var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(clipid);
- if (!clip) return false;
-
- clip.setData(trans, null, clipid.kGlobalClipboard);
- //Copy to clipboard end
- var copyStr = PhProxy_url_creator.depoxify(copytext);
- copyStr = (copyStr.length > 43) ? copyStr.substr(0,20) + '...' + copyStr.substr(copyStr.length-20,20) : copyStr;
- alert(stringsBundle.getString('Alert1') +' ' + copyStr + '\n' + stringsBundle.getString('Alert3'));
- },
- //New features on 3.0.3K
- is_this_vaid_phproxy_server: function (link)
- {
- //first test if server is valid PhProxy server then test if server works on index.php or not
- return /aHR0cDovL|d3d3L/.test(this.fix_url(link))
- && (/\/[^\/\?]*\?/.exec(this.fix_url(link))=="/" + PhProxy_prefs.read_str('phpIndex') + "?");
- },
- //This function is grabed from UrlbarExt 1.4.8(https://addons.mozilla.org/en-US/firefox/addon/8758)
- fix_url: function (aURL)
- {
- var d = decodeURIComponent(aURL);
- if (/\%[a-fA-F0-9]{2}/g.test(d)) {
- d = decodeURIComponent(d);
- }
- return d;
- },
- show_notification_on_unknown_servers: function (aURL){
- document.getElementById("Ph.Status.add-new-server-label").hidden = false;
- this.unkonwn_server = aURL.replace(/\/[^\/]*$/,"") + "/";
- },
- hide_notification_on_unknown_servers: function () {
- document.getElementById("Ph.Status.add-new-server-label").hidden = true;
- this.unkonwn_server = null;
- },
-
- open_secure : function (data) {
- var data = PhProxy_url_creator.proxify.apply_filter(data, "proxify");
- if( data )
- PhProxy.open_in.current_tab(data);
- },
-
- open_secure_in_new_tab : function (data) {
- var data = PhProxy_url_creator.proxify.apply_filter(data, "proxify");
- if( data )
- PhProxy.open_in.new_tab(data);
- }
- };
-
- var PhProxy_windows = {
- stringsBundle : null,
-
- initial : function(){
- stringsBundle=document.getElementById("Ph.Main.Bundle");
- },
-
- //Bookmarks
- bookmarks_context_menu : function (index) {
- var bmsvc = Components.classes["@mozilla.org/browser/nav-bookmarks-service;1"]
- .getService(Components.interfaces.nsINavBookmarksService);
- var nodeItemId=PlacesUtils.getConcreteItemId(document.popupNode.node);
- var nodeURI=bmsvc.getBookmarkURI(nodeItemId).spec;
- index == 1 ? PhProxy.open_secure(nodeURI) : PhProxy.open_secure_in_new_tab(nodeURI);
- },
-
- //Statusbar
- change_icon_color : function(color){
- if(!(content.document.location.href).match(PhProxy_prefs.read_str('curURL')))
- document.getElementById("Ph-Status-Icon").setAttribute('status', color);
- },
-
- onleftclick : function(event){
- if (event.button==0)
- if (PhProxy.unkonwn_server) {
- PhProxy_prefs.write_str("curURL", PhProxy.unkonwn_server);
- PhProxy_prefs.write_str("PrType", "1");
- //Alert for new changes
- alert(stringsBundle.getString('Alert11') + " "
- + PhProxy.unkonwn_server + "\n"
- + stringsBundle.getString('Alert12'));
- //Must place after all parts which need PhProxy.unkonwn_server
- //Remove notification label
- PhProxy.hide_notification_on_unknown_servers(this.selected_page_href);
- //force to process new URL
- var aURL = {spec:null}; //Generate a vertual aURL
- aURL.spec = content.document.location.href;
- PhProxy.process_new_URL(aURL);
- }
- else
- this.context(parseInt(PhProxy_prefs.read_str('LeftClick')));
- },
-
- show_alert_in_statusbar : function(msg){
- document.getElementById('Ph.Status.Label').value = document.getElementById("Ph.Main.Bundle").getString(msg);
- document.getElementById('Ph.Status.Label').hidden=false;
- setTimeout(function() {
- document.getElementById('Ph.Status.Label').hidden=true;
- }, 3000);
- },
-
- context : function(index, extra_index){
- const oURL = content.document.location.href;
- switch(index){
- case 0:
- const sURL=PhProxy_prefs.read_str('curURL');
- if(oURL.match(sURL))
- alert(stringsBundle.getString('Alert2'));
- else{
- data = PhProxy_url_creator.proxify.apply_filter(oURL, "proxify");
- if( data )
- PhProxy.open_in.current_tab(data);
- }
- break;
- case 3:
- window.openDialog('chrome://inbasicph/content/Options.xul','Ph.Option.Window',
- 'toolbar, centerscreen, chrome, resizable').focus();
- break;
- case 4:
- window.openDialog('chrome://inbasicph/content/About.xul',
- 'Ph.About.Window','centerscreen, chrome, resizable').focus();
- break;
- case 5:
- switch (extra_index) {
- case 0: //Changing privacy type
- case 1:
- case 2:
- PhProxy_prefs.write_str('privacyLevel', extra_index.toString() );
- break;
- default: //Changing cache type
- PhProxy_prefs.write_str('cacheType', (extra_index-3).toString() );
- }
- //update menu for all windows
- var wm =Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator);
- var browserEnumerator = wm.getEnumerator("navigator:browser");
- while(browserEnumerator.hasMoreElements()) //maybe more than 1 window opens!!
- {
- var dc = browserEnumerator.getNext().document;
- //Statusbar radio boxs
- dc.getElementById('Ph-Status-PH8-RadioG1').childNodes[parseInt(PhProxy_prefs.read_str('privacyLevel'))].setAttribute("checked", true);
- dc.getElementById('Ph-Status-PH8-RadioG2').childNodes[parseInt(PhProxy_prefs.read_str('cacheType'))].setAttribute("checked", true);
- }
- break;
- case 6:
- //update default server
- PhProxy_object.default_server.update(true, extra_index);
- break;
- default:
- /* Read Clipboard */
- var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
- if (!clip){
- alert("Clipboard copy problem!");
- return ;
- }
- var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
- if (!trans){
- alert("Clipboard copy problem!");
- return ;
- }
- trans.addDataFlavor("text/unicode");
- clip.getData(trans, clip.kGlobalClipboard);
- var str = new Object();
- var strLength = new Object();
- trans.getTransferData("text/unicode", str, strLength);
- if (str) str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
- if (str) pastetext = str.data.substring(0, strLength.value / 2);
- /* End Read Clipboard */
- if(pastetext){
- if (index==1) PhProxy.open_secure(pastetext);
- else PhProxy.open_secure_in_new_tab(pastetext);
- }
- else
- alert(stringsBundle.getString('Alert4'));
- }
- }
- };
-
- /**Read Write Pref */
- var PhProxy_prefs = {
- prefs: Components.classes["@mozilla.org/preferences-service;1"]
- .getService(Components.interfaces.nsIPrefService).getBranch("InBasic.PhProxy."),
-
- read_str : function (id) {
- return this.prefs.getCharPref(id);
- },
- write_str : function (id, sData) {
- this.prefs.setCharPref(id, sData);
- },
- read_bool : function (id) {
- return this.prefs.getBoolPref(id);
- },
- write_bool : function (id, sData) {
- this.prefs.setBoolPref(id, sData);
- }
- }
-
- /*************************************************************************Window phv_servers_listener *****************************************************/
- PhProxy_object = PhProxy;
- window.addEventListener("load", function() {PhProxy_object.initial()}, false);
- window.addEventListener("unload", function() {PhProxy_object.terminate()}, false);